<?php 
class product_plugin_popular extends abstract_product_plugin {


    public function getPopularProducts($limit) {
		
        $query = $this->pdo->prepare("SELECT * FROM " . $this->db_prefix . "product p 
            LEFT JOIN " . $this->db_prefix . "product_to_store p2s 
            ON (p.product_id = p2s.product_id) 
            WHERE p.status = '1' 
            AND p.date_available <= NOW() 
            AND p2s.store_id = :store_id
            ORDER BY p.viewed, 
            p.date_added 
            DESC LIMIT :limit");

        $limit = (int) $limit; 
        $query->bindParam(':limit', $limit, PDO::PARAM_INT);
        $query->bindParam(':store_id', $this->site_id, PDO::PARAM_INT);
        $query->execute();

        $product_data = array();

        while ($product = $query->fetchObject('class_product')) {
            $product_data[$product->get_id()] = $product;	
        }

        return $product_data;
	}

